const { Service } = require("egg");

class DownloadService extends Service {
    async list() {
        return await this.app.model.Download.findAll(
            {
                order: [['updateAt', 'DESC']],
                raw: true,
            }
        );
    }
    async create(data) {
        return await this.app.model.Download.create(data);
    }

    async delete(id) {
        return await this.app.model.Download.destroy({
            where: { id },
        });
    }

    async update(id, updateData) {
        const updated = await this.app.model.Download.update(updateData, {
            where: { id },
        });
        return updated[0] ? updated[0] : null;

    }
}

module.exports = DownloadService;
